package com.gin.no_gay_alliance.viewmodel;

import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;

import com.gin.nga.response.ReplyLocation;

/**
 * 回复结果
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/16 17:08
 **/
public class PostResult implements Parcelable {
    public static final Creator<PostResult> CREATOR = new Creator<PostResult>() {
        @Override
        public PostResult createFromParcel(Parcel in) {
            return new PostResult(in);
        }

        @Override
        public PostResult[] newArray(int size) {
            return new PostResult[size];
        }
    };
    public Long forumId;
    public Long topicId;
    public Integer page;
    public Long replyId;

    public PostResult(ReplyLocation location) {
        forumId = location.getForumId();
        topicId = location.getTopicId();
        page = location.getPage();
        replyId = location.getReplyId();
    }

    protected PostResult(Parcel in) {
        if (in.readByte() == 0) {
            forumId = null;
        } else {
            forumId = in.readLong();
        }
        if (in.readByte() == 0) {
            topicId = null;
        } else {
            topicId = in.readLong();
        }
        if (in.readByte() == 0) {
            page = null;
        } else {
            page = in.readInt();
        }
        if (in.readByte() == 0) {
            replyId = null;
        } else {
            replyId = in.readLong();
        }
    }

    public Intent buildIntent() {
        Intent intent = new Intent();
        intent.putExtra(PostResult.class.getName(), this);
        return intent;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (forumId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(forumId);
        }
        if (topicId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(topicId);
        }
        if (page == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(page);
        }
        if (replyId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeLong(replyId);
        }
    }
}
